﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Maticsoft.DBUtility;
using EnvironmentManagerSystem.MODE;
using MySql.Data.MySqlClient;
using System.Web;

namespace EnvironmentManagerSystem.BLL
{
    public class HtroleService
    {

        #region 获取功能列表
        public static HtroleDataCollection GetList()
        {
            try
            {
                HtroleDataCollection list = new HtroleDataCollection();
                string strSql = @"SELECT * FROM tbs001_htrole";
                using (MySqlDataReader dr = DbHelperMySQL.ExecuteReader(strSql))
                {
                    while (dr.Read())
                    {
                        HtroleData model = new HtroleData();
                        model.ID = (int)dr["ID"];
                        model.Names = dr["Names"].ToString();
                        list.Add(model);
                    }
                }
                return list;
            }
            catch
            {
                return null;
            }
        }
        #endregion

        #region 获取功能列表
        public static HtroleDataCollection GetLists(int RoleID)
        {
            try
            {
                HtroleDataCollection list = new HtroleDataCollection();
                string strSql = @"SELECT c.Names,c.ID FROM tbs001_h a,tbs001_role b,tbs001_htrole c WHERE a.RID=b.ID AND a.FID=c.ID AND b.ID=" + RoleID;
                using (MySqlDataReader dr = DbHelperMySQL.ExecuteReader(strSql))
                {
                    while (dr.Read())
                    {
                        HtroleData model = new HtroleData();
                        model.ID = (int)dr["ID"];
                        model.Names = dr["Names"].ToString();
                        list.Add(model);
                    }
                }
                return list;
            }
            catch
            {
                return null;
            }
        }
        #endregion

        #region 添加角色权限、删除角色权限
        //添加角色权限
        public static bool InsertRoleFunction(int RoleID, int FunctionID)
        {
            try
            {
                string strSql = string.Format(@"INSERT INTO tbs001_h (RID,FID,Value) VALUES ({0},{1},1)", RoleID, FunctionID);
                return DbHelperMySQL.ExecuteSql(strSql) > 0 ? true : false;
            }
            catch
            {
                return false;
            }
        }
        //删除角色权限
        public static bool DeleteRoleFunction(int RoleID, int FunctionID)
        {
            try
            {
                string strSql = string.Format(@"delete from tbs001_h where RID={0} and FID={1}", RoleID, FunctionID);
                return DbHelperMySQL.ExecuteSql(strSql) > 0 ? true : false;
            }
            catch
            {
                return false;
            }
        }

        #endregion
    }
}
